
//
//  MBProgressHUD+Bill.m
//  bill
//
//  Created by Demon on 16/1/21.
//  Copyright © 2017年 Demon. All rights reserved.
//

#import "MBProgressHUD+Bill.h"

@implementation MBProgressHUD (Bill)

+ (MBProgressHUD *)showWaitaAtivityindicatorview {
    MBProgressHUD *hud = [self showMessage:nil toView:nil];
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    [hud hideAnimated:YES];
    return hud;
}

+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
    if (view == nil) view = WINDOW;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = text;
    hud.userInteractionEnabled = NO;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1];
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view {
    [self show:error icon:@"hud_error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view {
    [self show:success icon:@"hud_success.png" view:view];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    //    hud.customView = YES;
    return hud;
}

+ (MBProgressHUD *)showIndeterminate:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[MBProgressHUD class]]].color = [UIColor whiteColor];
    MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hub.bezelView.color = [UIColorHex(333333) colorWithAlphaComponent:1];;
    hub.mode = MBProgressHUDModeIndeterminate;
    [UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[MBProgressHUD class]]].color = [UIColor whiteColor];
    return hub;
}

+ (MBProgressHUD *)showIndeterminateAndText:(UIView *)view text:(NSString *)text {
    MBProgressHUD *hub = [self showIndeterminate:view];
    hub.label.text = text;
    hub.label.textColor = [UIColor whiteColor];
    hub.label.textAlignment = 1;
    hub.label.font = [UIFont systemFontOfSize:16];
    return hub;
}

+ (void)showSuccess:(NSString *)success {
    [self showSuccess:success toView:nil];
}

+ (void)showError:(NSString *)error {
    [self showError:error toView:nil];
}

+ (MBProgressHUD *)showMessage:(NSString *)message {
    return [self showMessage:message toView:nil];
}

+ (void)hideHUDForView:(UIView *)view {
    [self hideHUDForView:view animated:YES];
}

+ (void)hideHUD {
    [self hideHUDForView:nil];
}



@end
